#ifndef __BRANCH1_BASE_TRIGGER_H__
#define __BRANCH1_BASE_TRIGGER_H__
#include "Branch1BaseConfig.h"
#include <daisy/EventSystem.h>
#include "TriggerConditions.h"
#include "TriggerEventHandler.h"
#include "TriggerAction.h"
#include "TriggerEventHandlerPoling.h"
namespace DAISY
{
	typedef boost::shared_ptr<TriggerConditions>  TriggerConditionsPtr;
	typedef boost::shared_ptr<TriggerAction>  TriggerActionPtr;
	class _BranchBaseExport Trigger:public TriggerEventHandlerCallback
	{
	protected:
		typedef std::pair<TriggerEventHandlerPtr, EventManager*> EventHandlerPair;
		typedef std::vector<EventHandlerPair> EventHandlerList;
		typedef std::vector<TriggerConditionsPtr> ConditionsList;
		typedef std::vector<TriggerActionPtr> ActionList;
	public:
		Trigger(int id);
		virtual ~Trigger(void);


		void addEventHandler(TriggerEventHandlerPtr eh, EventManager * manager);
		void addAction(TriggerActionPtr action);


		void addConditions(TriggerConditionsPtr conditions);
		void clearEventHandler(void);
		void enable(void);
		void disable(void);

	private:

		void execute(Event * evt);
		void _action(Event * evt);
		void _start(void);
		void _stop(void);
		const int _id;
		EventHandlerList _eventHandlers;
		ConditionsList _conditionses;
		ActionList _actions;
		bool _isEnable;
	};
	typedef boost::shared_ptr<Trigger>  TriggerPtr;
}


#endif